package com.gofaraway.dao.mysql.trunk.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.core.toolkit.CollectionUtils;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.gofaraway.dao.mysql.dto.ShipmentResponseDTO;
import com.gofaraway.dao.mysql.dto.ShipmentSearchRequestDTO;
import com.gofaraway.dao.mysql.trunk.entity.StoShipment;
import com.gofaraway.dao.mysql.trunk.mapper.StoShipmentMapper;
import com.gofaraway.dao.mysql.trunk.service.IStoShipmentService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.apache.commons.lang3.StringUtils;
import org.springframework.stereotype.Service;

import java.util.Collections;
import java.util.List;

/**
 * <p>
 * shipment表扩展字段 服务实现类
 * </p>
 *
 * @author 1065277
 * @since 2024-01-18
 */
@Service
public class StoShipmentServiceImpl extends ServiceImpl<StoShipmentMapper, StoShipment> implements IStoShipmentService {

    @Override
    public IPage<StoShipment> pageQuery(ShipmentSearchRequestDTO queryRequest) {
        IPage<StoShipment> iPage = new Page<>(queryRequest.getCurrent(), queryRequest.getSize());
        LambdaQueryWrapper<StoShipment> lambdaQuery = Wrappers.lambdaQuery();
        lambdaQuery.between(StringUtils.isNotBlank(queryRequest.getStartDate()) && StringUtils.isNotBlank(queryRequest.getEndDate()),
                StoShipment::getActualArrivalTime,
                queryRequest.getStartDate(),
                queryRequest.getEndDate())
                .eq(StringUtils.isNotBlank(queryRequest.getShipmentNo()), StoShipment::getShipmentNo, queryRequest.getShipmentNo())
                .orderByDesc(StoShipment::getActualArrivalTime);
        return baseMapper.selectPage(iPage, lambdaQuery);
    }
}
